package cn.wk.basic.utils;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
@Component
public class SendMail {
    //发送邮件注入
    @Autowired
    private JavaMailSender javaMailSender;

    public void send(String mail,String name) throws MessagingException {
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
        //设置发送人
        mimeMessageHelper.setFrom("wjyb3134@qq.com");
        //设置收件人
        mimeMessageHelper.setTo(mail);
        //设置邮件内容
        mimeMessageHelper.setText("<h1>"+name+"</h1><a href=\"http://127.0.0.1:8081/#/HomePage\">"+"点击查看"+"</a>",true);
        //设置邮件标题
        mimeMessageHelper.setSubject("审核通知");
        //发送邮件
        javaMailSender.send(mimeMessage);
    }
}
